package cn.smartorigin.soas.frame.tab;

import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;

import javax.swing.plaf.metal.MetalTabbedPaneUI;

import cn.smartorigin.soas.frame.SoasUtil;

public class CellTabbedPaneUI extends MetalTabbedPaneUI {
	 private CellTabbedPane tab = null;
	    private int firstTabIndent = 5;

	    public CellTabbedPaneUI(CellTabbedPane tab) {
	        this.tab = tab;
	    }

	    @Override
	    protected Rectangle getTabBounds(int tabIndex, Rectangle dest) {
	        Rectangle bounds = super.getTabBounds(tabIndex, dest);
	        //give first tab a leading space.
	        bounds.x += firstTabIndent;
	        return bounds;
	    }

	    @Override
	    protected void paintTabBorder(Graphics g, int tabPlacement,
	            int tabIndex, int x, int y, int w, int h,
	            boolean isSelected) {

	        //paint nothing, expect the bottom line in the leading indent.
	        g.setColor(SoasUtil.TAB_BOTTOM_LINE_COLOR);
	        int lineY = tab.getPreferredTabHeight() - 1;
	        g.drawLine(0, lineY, firstTabIndent, lineY);
	    }

	    @Override
	    protected void paintTabBackground(Graphics g, int tabPlacement,
	            int tabIndex, int x, int y, int w, int h,
	            boolean isSelected) {
	        //paint nothing
	    }

	    @Override
	    protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
	        int width = super.calculateTabWidth(tabPlacement, tabIndex, metrics);
	        //use this to remove the tab between tabs.
	        return width - 5;
	    }

	    @Override
	    protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
	        return tab.getPreferredTabHeight();
	    }

}
